#ifndef RESOURCETRACKER_H
#define RESOURCETRACKER_H

#include <cv.h>
#include <highgui.h>

class VideoPointTagSequence;
class VideoGestureTagSequence;

//FIX : big three?

class ResourceTracker {
public:
	ResourceTracker( const char* cfgXMLFileString );

//Example:
//	ResourceTracker* rt = new ResourceTracker( "../config/runtimeSettings/cfg.xml" );
//	rt->loadCategory("TestData");
	
	
	void loadCategory( const char* categoryNameString );
	//TODO : use ref instead? Ref appears non-standard in OpenCV context
	cv::Mat getMat( const char* imageNameString );
	cv::Point getPointTag( const char* imageNameString );
	cv::Ptr< cv::VideoCapture > getFileVideoCapture( const char* videoNameString );
	cv::Ptr< VideoPointTagSequence > getPointTags( const char* videoNameString );
	cv::Ptr< VideoGestureTagSequence > getGestureTags( const char* videoNameString );
	
	// -- For video recording -- //
	// Used in AVIRecorder
	void startVideoWriter( const char* videoNameString, int captureWidth, int captureHeight, int fps );
	void writeFrameToVideo( IplImage* frame ); //Update to OpenCV/C++
	void releaseVideoWriter();
	
	// -- For video point tagging -- //
	// Used in AVITagger
	void startVideoTagging( const char* videoNameString );
	void tagVideo( int x, int y );
	void stopVideoTagging();
	
	//Used in AbstractHandTrackerTest when in recording mode
	void startVideoTagging( const char* videoNameString, const char* tagListNameString );
	void stopVideoTagging(int firstFrameTagged, int trackingRectWidth, int trackingRectHeight );
	
	// -- For video gesture tagging -- //
	// Used in AVIGestureTagger
	void startVideoGestureTagging( const char* videoNameString );
	void tagVideoHandOpen();
	void tagVideoHandClosed();
	void stopGestureVideoTagging();
	
	~ResourceTracker();
	
private:
	CvFileStorage* cfgFile;
	CvFileStorage* dataLocationsFile;
	const char* dataLocationsPrefixString;
	const char* dataLocationsFileString;
	
	void addResourceFile( const char* resourceNameString, const char* localResourceFileName );
	
	char* getResourceLocationString_orphanOut( const char* resourceNameString );
	char* getPointTagNameString_orphanOut( const char* resourceNameString );
	char* getLocalGestureTagFileXMLNameString_orphanOut( char* resourceNameString );
	
	char* getGlobalFileNameString_orphanOut( const char* localFileNameString );
	
	char* getLocalAVIFileNameString_orphanOut( const char* videoNameString );
	char* getLocalTagFileXMLNameString_orphanOut( char* resourceNameString );
	
	char* getGestureTagNameString_orphanOut( const char* resourceNameString );

	//TODO RAT
	//char* strAppend_orphanOut( const char* strOne, const char* strTwo );
	
	void setResourceNameString( const char* resourceNameString );
	void unsetResourceNameString();
	
	CvVideoWriter* videoWriter;
	
	CvMemStorage* storage_videoTags;
	CvSeq* videoTags;
	
	char* resourceNameString;
	
	int tagCount;
};

class VideoPointTagSequence {
public:
	
	VideoPointTagSequence(CvFileStorage* fs);
	
	~VideoPointTagSequence();
	
	cv::Point getNextPointTag();

	int tagCount;
	int frameCount;
	int currentTag;
	
	int firstFrameTagged;
	int trackingRectWidth;
	int trackingRectHeight;
	
private:
	CvFileStorage* fs;
	CvSeq* seq;
};

class VideoGestureTagSequence {
public:
	
	VideoGestureTagSequence(CvFileStorage* fs);
	
	~VideoGestureTagSequence();
	
	char getNextGestureTag();
	
	int tagCount;
	int frameCount;
	int currentTag;
private:
	CvFileStorage* fs;
	CvSeq* seq;
};
	
#endif